package com.ltxtiyu.video.api;


import com.alibaba.dubbo.config.annotation.Reference;
import com.ltxtiyu.video.common.DataGridParam;
import com.ltxtiyu.video.common.JsonTool;
import com.ltxtiyu.video.common.RetEnum;
import com.ltxtiyu.video.service.app.OauthService;
import com.ltxtiyu.video.service.app.UserService;
import com.ltxtiyu.video.tool.AliTool;
import com.ltxtiyu.video.tool.ParamTool;
import com.ltxtiyu.video.tool.Tool;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/apiUser")
public class ApiUser {
    @Reference
    UserService userService;
    @Reference
    OauthService oauthService;
    /**
     * 我的设置
     * @param request
     * @return
     */
    @RequestMapping("/mySetting")
    public String mySetting(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return userService.mySetting(params);
    }

    /**
     * 绑定手机号
     * @param request
     * @return
     */
    @RequestMapping("/bindMobile")
    public String bindMobile(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return oauthService.bindMobile(params);
    }
    /**
     * 我的个人资料
     * @param request
     * @return
     */
    @RequestMapping("/myProfile")
    public String myProfile(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return userService.myProfile(params);
    }

    /**
     * 修改我的个人资料
     * @param request
     * @return
     */
    @RequestMapping("/updateMyInfo")
    public String updateMyInfo(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return userService.updateMyInfo(params);
    }

    /**
     * 我的首页 | 查看别人的首页
     * @param request
     * @return
     */
    @RequestMapping("/userIndex")
    public String userIndex(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("userId",userId);
        return userService.userIndex(params);
    }

    /**
     * 关注用户
     * @param request
     * @return
     */
    @RequestMapping("/follow")
    public String follow(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return userService.follow(params);
    }

    /**
     * 关注用户
     * @param request
     * @return
     */
    @RequestMapping("/unfollow")
    public String unfollow(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return userService.unfollow(params);
    }

    /**
     * 添加意见反馈
     * @param request
     * @return
     */
    @RequestMapping("/addFeedback")
    public String addFeedback(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return userService.addFeedback(params);
    }

    /**
     * 我的关注/粉丝列表
     * @param request
     * @return
     */
    @RequestMapping("/listRelationUser")
    public String listRelationUser(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("userId",userId);
        return userService.listRelationUser(params);
    }


}
